package com.huawei.dli.flink.sye.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.OutputStream;
import java.io.PrintStream;

public class Log4jPrintStream  extends PrintStream{
  private static final Logger logger = LoggerFactory.getLogger("SystemOut");
  private static PrintStream instance = new Log4jPrintStream(System.out);

  private Log4jPrintStream(OutputStream out) {
    super(out);
  }

  public static void redirectSystemOut() {
    System.setOut(instance);
  }

  @Override
  public void print(boolean b) {
    println(b);
  }
  @Override
  public void print(char c) {
    println(c);
  }
  @Override
  public void print(char[] s) {
    println(s);
  }
  @Override
  public void print(double d) {
    println(d);
  }
  @Override
  public void print(float f) {
    println(f);
  }
  @Override
  public void print(int i) {
    println(i);
  }
  @Override
  public void print(long l) {
    println(l);
  }

  @Override
  public void print(Object obj) {
    println(obj);
  }
  @Override
  public void print(String s) {
    println(s);
  }
  @Override
  public void println(boolean x) {
    logger.info(String.valueOf(x));
  }
  @Override
  public void println(char x) {
    logger.info(String.valueOf(x));
  }
  @Override
  public void println(char[] x) {
    logger.info(x == null ? null : new String(x));
  }
  @Override
  public void println(double x) {
    logger.info(String.valueOf(x));
  }
  @Override
  public void println(float x) {
    logger.info(String.valueOf(x));
  }
  @Override
  public void println(int x) {
    logger.info(String.valueOf(x));
  }
  @Override
  public void println(long x) {
    logger.info(String.valueOf(x));
  }
  @Override
  public void println(Object x) {
    logger.info(String.valueOf(x));
  }
  @Override
  public void println(String x) {
    logger.info(String.valueOf(x));
  }
}
